<template>
  <div class="home">
    <section class="hero">
      <div class="container">
        <div class="hero-content">
          <h1>柯基工具箱</h1>
          <p>一站式解决您的办公需求，提高工作效率</p>
          <div class="hero-buttons">
            <router-link to="/text-tools" class="btn">开始使用</router-link>
            <router-link to="/membership" class="btn btn-outline">会员计划</router-link>
          </div>
          <div class="quick-actions" v-if="!isLoggedIn">
            <span>已有账号？</span>
            <router-link to="/login">立即登录</router-link>
            <span>|</span>
            <router-link to="/register">快速注册</router-link>
          </div>
        </div>
      </div>
    </section>

    <!-- 会员推广部分 -->
    <!-- <section class="pro-banner" v-if="!isPro">
      <div class="container">
        <div class="pro-banner-content">
          <div class="pro-banner-info">
            <h2>升级到Pro会员</h2>
            <p>解锁所有高级功能，享受更快捷、更强大的办公体验</p>
            <ul class="pro-features">
              <li><el-icon><Check /></el-icon> OCR图文识别</li>
              <li><el-icon><Check /></el-icon> 高级格式转换</li>
              <li><el-icon><Check /></el-icon> PDF高级操作</li>
              <li><el-icon><Check /></el-icon> AI辅助生成</li>
            </ul>
            <div class="pro-actions" v-if="isLoggedIn">
              <el-button type="warning" @click="upgradeNow">立即升级</el-button>
            </div>
            <div class="pro-actions" v-else>
              <el-button type="warning" @click="loginFirst">登录后升级</el-button>
            </div>
          </div>
          <div class="pro-banner-image">
            <img src="@/assets/images/pro-illustration.svg" alt="Pro会员" />
          </div>
        </div>
      </div>
    </section> -->

    <section class="features">
      <div class="container">
        <h2 class="section-title">主要功能</h2>
        <div class="feature-grid">
          <!-- 文档处理工具 -->
          <router-link to="/text-tools" class="feature-card card">
            <div class="feature-icon">
              <el-icon size="32"><Document /></el-icon>
            </div>
            <h3>文档处理工具</h3>
            <p>包括格式转换、文本处理、文件压缩等功能，高效处理各类文档</p>
          </router-link>

          <!-- 图像工具 -->
          <router-link to="/image-tools" class="feature-card card">
            <div class="feature-icon">
              <el-icon size="32"><Picture /></el-icon>
            </div>
            <h3>图像工具</h3>
            <p>图片处理、格式转换、缩放裁剪、水印添加等图像处理功能</p>
          </router-link>

          <!-- 格式转换工具 -->
          <router-link to="/converters" class="feature-card card">
            <div class="feature-icon">
              <el-icon size="32"><SwitchButton /></el-icon>
            </div>
            <h3>格式转换工具</h3>
            <p>在线转换各种文件格式，支持Word、PDF、图片等互转</p>
          </router-link>

          <!-- 效率工具 -->
          <router-link to="/efficiency-tools" class="feature-card card">
            <div class="feature-icon">
              <el-icon size="32"><Timer /></el-icon>
            </div>
            <h3>效率工具</h3>
            <p>番茄钟、任务管理、时间戳转换、二维码生成等提升工作效率的工具</p>
          </router-link>
        </div>
      </div>
    </section>

    <section class="popular-tools">
      <div class="container">
        <h2 class="section-title">热门工具</h2>
        <div class="tools-grid">
          <ToolCard
            v-for="(tool, index) in popularTools"
            :key="index"
            :title="tool.name"
            :description="tool.description"
            :icon="tool.icon"
            :link="tool.link"
            :is-pro="tool.isPro"
          />
        </div>
      </div>
    </section>

    <!-- 最近使用的工具 -->
    <section class="recent-tools" v-if="isLoggedIn && latestTools.length > 0">
      <div class="container">
        <h2 class="section-title">最近使用</h2>
        <div class="tools-grid">
          <ToolCard
            v-for="(tool, index) in latestTools"
            :key="index"
            :title="tool.name"
            :description="'继续使用这个工具'"
            :icon="'Tools'"
            :link="tool.link"
            :is-pro="tool.isPro"
            button-text="继续使用"
          />
        </div>
      </div>
    </section>

    <section class="usage-section">
      <div class="container">
        <div class="usage-wrapper">
          <div class="usage-title-section">
            <el-icon size="28" class="usage-icon"><Guide /></el-icon>
            <h2>快速使用指南</h2>
          </div>
          <UsageGuide :is-open="true">
            <template #title>如何高效使用办公工具箱</template>
            <template #content>
              <div class="guide-steps">
                <div class="step-item">
                  <div class="step-number">1</div>
                  <div class="step-content">
                    <h4>选择工具</h4>
                    <p>根据您的需求选择合适的工具分类</p>
                  </div>
                </div>
                <div class="step-item">
                  <div class="step-number">2</div>
                  <div class="step-content">
                    <h4>设置参数</h4>
                    <p>根据需要配置工具参数和上传文件</p>
                  </div>
                </div>
                <div class="step-item">
                  <div class="step-number">3</div>
                  <div class="step-content">
                    <h4>输入内容</h4>
                    <p>输入或上传需要处理的文本、图像等内容</p>
                  </div>
                </div>
                <div class="step-item">
                  <div class="step-number">4</div>
                  <div class="step-content">
                    <h4>获取结果</h4>
                    <p>处理完成后下载或复制处理结果</p>
                  </div>
                </div>
              </div>
              <div class="pro-tip" v-if="!isPro">
                <el-icon><Star /></el-icon>
                <span><strong>提示：</strong> 升级到Pro会员可以解锁所有高级功能，包括批量处理、AI辅助和更多专业工具</span>
              </div>
            </template>
          </UsageGuide>
        </div>
      </div>
    </section>
  </div>
</template>

<script setup>
/**
 * 首页组件
 * 展示网站主要功能和热门工具
 */
import { computed } from 'vue';
import { useStore } from 'vuex';
import { Document, Timer, Picture, SwitchButton, Check, Tools, Guide, Star } from '@element-plus/icons-vue';
import UsageGuide from '../../components/common/UsageGuide.vue';
import ToolCard from '../../components/ui/ToolCard.vue';
import { useRouter } from 'vue-router';

const store = useStore();
const router = useRouter();

// 用户状态
const isLoggedIn = computed(() => store.state.isLoggedIn);
const isPro = computed(() => store.getters.isPro);
const latestTools = computed(() => store.state.latestTools.map(tool => {
  return {
    ...tool,
    link: getLinkByToolName(tool.name)
  };
}));

// 根据工具名获取链接
function getLinkByToolName(name) {
  if (name.includes('文本格式化')) {
    return '/text-tools';
  } else if (name.includes('图像')) {
    return '/image-tools';
  } else if (name.includes('转换')) {
    return '/converters';
  } else if (name.includes('效率')) {
    return '/efficiency-tools';
  } else if (name.includes('数据')) {
    return '/data-tools';
  } else {
    return '/';
  }
}

// 热门工具列表
const popularTools = [
  {
    name: '文本格式化工具',
    description: '处理文本格式，包括大小写转换、去除多余空格等功能',
    link: '/text-tools',
    icon: 'Document',
    isPro: false
  },
  {
    name: '图片压缩工具',
    description: '批量压缩图片，保持清晰度的同时减小文件体积',
    link: '/image-tools',
    icon: 'Picture',
    isPro: false
  },
  {
    name: 'PDF转Word',
    description: 'PDF文件转换为可编辑的Word文档',
    link: '/converters',
    icon: 'Document',
    isPro: true
  },
  {
    name: 'OCR图文识别',
    description: '从图片中提取文字，支持多种语言',
    link: '/image-tools',
    icon: 'Reading',
    isPro: true
  }
];

// 打开登录窗口
const loginFirst = () => {
  router.push('/login');
};

// 升级会员
const upgradeNow = () => {
  document.querySelector('.user-avatar').click();
  setTimeout(() => {
    document.querySelector('[data-command="upgradeToPro"]')?.click();
  }, 100);
};
</script>

<style scoped>
.hero {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
  color: var(--white);
  padding: 80px 0;
  margin-bottom: 60px;
  box-shadow: 0 5px 20px rgba(var(--primary-color-rgb), 0.3);
}

.hero-content {
  text-align: center;
  max-width: 800px;
  margin: 0 auto;
}

.hero-content h1 {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 16px;
  letter-spacing: -0.5px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.hero-content p {
  font-size: 1.2rem;
  margin-bottom: 40px;
  opacity: 0.9;
}

.hero-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.hero-buttons .btn {
  min-width: 150px;
  font-weight: 600;
}

.btn {
  display: inline-block;
  padding: 10px 25px;
  border-radius: 4px;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.3s ease;
  cursor: pointer;
  background-color: var(--white);
  color: var(--primary-color);
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.btn-secondary {
  background-color: transparent;
  border: 1px solid var(--white);
  color: var(--white);
}

/* Pro会员推广部分 */
.pro-banner {
  background-color: rgba(var(--primary-color-rgb), 0.05);
  padding: 40px 0;
  margin-bottom: 40px;
}

.pro-banner-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 40px;
}

.pro-banner-info {
  flex: 1;
}

.pro-banner-info h2 {
  color: var(--warning-color);
  font-size: 1.8rem;
  margin-bottom: 15px;
}

.pro-banner-info p {
  color: var(--dark-gray);
  margin-bottom: 20px;
  font-size: 1.1rem;
}

.pro-features {
  list-style: none;
  padding: 0;
  margin: 0 0 25px 0;
}

.pro-features li {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--dark-gray);
}

.pro-features li .el-icon {
  color: var(--success-color);
}

.pro-actions {
  margin-top: 20px;
}

.pro-banner-image {
  flex: 1;
  display: flex;
  justify-content: center;
}

.pro-banner-image img {
  max-width: 100%;
  height: auto;
  max-height: 250px;
}

.section-title {
  text-align: center;
  margin-bottom: 40px;
  color: var(--primary-dark);
  position: relative;
  padding-bottom: 15px;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 3px;
  background-color: var(--primary-light);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 30px;
  margin-bottom: 60px;
}

.feature-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 30px 20px;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  text-decoration: none;
  color: inherit;
  border-radius: 12px;
  background-color: white;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  height: 100%;
}

.feature-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}

.feature-icon {
  background-color: var(--light-gray);
  color: var(--primary-color);
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  margin-bottom: 20px;
}

.feature-card h3 {
  font-size: 1.3rem;
  margin-bottom: 15px;
  color: var(--primary-dark);
}

.feature-card p {
  color: var(--dark-gray);
  margin-bottom: 20px;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 60px;
}

.popular-tools, .recent-tools {
  margin-bottom: 40px;
}

.usage-section {
  margin-bottom: 60px;
  padding: 40px 0;
  background-color: rgba(var(--primary-color-rgb), 0.03);
}

.usage-wrapper {
  max-width: 1200px;
  margin: 0 auto;
}

.usage-title-section {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 25px;
}

.usage-icon {
  color: var(--primary-color);
  background-color: rgba(var(--primary-color-rgb), 0.1);
  padding: 12px;
  border-radius: 50%;
  margin-right: 15px;
}

.usage-title-section h2 {
  font-size: 1.8rem;
  color: var(--primary-dark);
  margin: 0;
  font-weight: 600;
}

.guide-steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  padding: 10px 0 30px;
}

.step-item {
  display: flex;
  align-items: flex-start;
  background-color: white;
  padding: 20px 15px;
  border-radius: 12px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  height: 100%;
}

.step-item:hover {
  transform: translateY(-10px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.12);
}

.step-number {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  margin-right: 15px;
  flex-shrink: 0;
  font-size: 16px;
  box-shadow: 0 3px 6px rgba(var(--primary-color-rgb), 0.3);
}

.step-content {
  flex: 1;
}

.step-content h4 {
  margin: 0 0 8px 0;
  color: var(--primary-dark);
  font-size: 1.1rem;
  font-weight: 600;
}

.step-content p {
  margin: 0;
  color: var(--dark-gray);
  font-size: 0.95rem;
  line-height: 1.5;
}

.pro-tip {
  display: flex;
  align-items: center;
  background: linear-gradient(135deg, rgba(var(--pro-color-rgb), 0.08) 0%, rgba(var(--pro-color-rgb), 0.03) 100%);
  padding: 15px;
  border-radius: 8px;
  border-left: 4px solid var(--pro-color);
}

.pro-tip .el-icon {
  color: var(--pro-color);
  font-size: 20px;
  margin-right: 10px;
}

.pro-tip span {
  color: var(--dark-gray);
  font-size: 0.95rem;
}

.quick-actions {
  margin-top: 20px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

.quick-actions a {
  color: #fff;
  font-weight: 500;
  text-decoration: none;
  margin: 0 8px;
  transition: all 0.3s ease;
  padding: 4px 8px;
  border-radius: 4px;
}

.quick-actions a:hover {
  background-color: rgba(255, 255, 255, 0.15);
  text-decoration: underline;
}

@media (max-width: 768px) {
  .pro-banner-content {
    flex-direction: column;
  }
  
  .pro-banner-image {
    order: -1;
  }
  
  .feature-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 992px) {
  .guide-steps {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 576px) {
  .guide-steps {
    grid-template-columns: 1fr;
  }
}
</style> 